package top.vains.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.vains.entity.Result;
import top.vains.entity.Role;
import top.vains.entity.customer.Pagination;
import top.vains.service.IRoleService;
import top.vains.util.ResultUtils;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author vains
 * @since 2020-02-17
 */
@RestController
@RequestMapping("/role")
@Api(tags = "角色接口，更新指定的角色")
public class RoleController {

    private final IRoleService roleService;

    @Autowired
    public RoleController(IRoleService roleService) {
        this.roleService = roleService;
    }

    @GetMapping("/getRoles")
    @ApiOperation(value = "获取角色信息", notes = "获取角色信息")
    public Result getUserRole() {
        List<Role> list = roleService.list();
        return ResultUtils.success("查询成功！", list);
    }

    @GetMapping("/getRole")
    @ApiOperation(value = "获取角色信息", notes = "获取角色信息")
    public Result getRole(Pagination pagination) {
        roleService.getRoles(pagination);
        return ResultUtils.success("查询成功！", pagination);
    }

    @PostMapping("/saveRole")
    @ApiOperation(value = "添加角色信息", notes = "添加角色信息")
    public Result saveRole(@RequestBody Role role) {
        roleService.save(role);
        return ResultUtils.success("添加成功！");
    }

    @PostMapping("/updateRole")
    @ApiOperation(value = "修改角色信息", notes = "修改角色信息")
    public Result updateRole(@RequestBody Role role) {
        roleService.updateById(role);
        return ResultUtils.success("修改成功！");
    }

}
